package 线程停止;
//使用stop()释放锁会给数据造成不一致性的结果，如果出现这样的情况，程序处理的数据就有可能遭到破坏，导致程序执行的流程错误
class SynchronizedObject
{
	private String username="a";
	private String password="aa";
	public String getUsername()
	{
		return username;
	}
	public void setUsername(String username)
	{
		this.username=username;
	}
	public String getPassword()
	{
		return username;
	}
	public void setPassword(String password)
	{
		this.password=password;
	}
	synchronized public void printString(String username,String password)
	{
		try {
			this.password=password;
			this.username=username;
			Thread.sleep(10000);
			
		}
		catch(InterruptedException e )
		{
			e.printStackTrace();
		}
	}
}
class MyThreadssm extends Thread
{
	private SynchronizedObject object;
	public MyThreadssm(SynchronizedObject object)
	{
		this.object=object;
	}
	public void run()
	{
		object.printString("bb", "b");
	}
}
public class Test1_43 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try
		{
			SynchronizedObject object=new SynchronizedObject();
			MyThreadssm thread=new MyThreadssm(object);
			thread.start();
			Thread.sleep(500);
			thread.stop();
			System.out.println(object.getUsername()+" "+object.getPassword());
			
		}
		catch(InterruptedException e)
		{
			e.printStackTrace();
		}

	}

}
